# import cv2
# from ultralytics import YOLO
# import threading
# import queue
#
#
# class RISyolo:
#     def __init__(self, model_path, camera_id=4, max_queue_size=10):
#         self.model = YOLO(model_path)
#         self.camera_id = camera_id
#         self.frame_queue = queue.Queue(maxsize=max_queue_size)
#         self.capture_thread = threading.Thread(target=self.capture_frames, daemon=True)
#         self.capture_thread.start()
#
#     def capture_frames(self):
#         cap = cv2.VideoCapture(self.camera_id)
#         while True:
#             success, frame = cap.read()
#             if not success:
#                 break
#
#             # Perform object detection on the frame
#             results = self.model(frame)
#
#             # Draw results on the frame
#             annotated_frame = results[0].plot()
#
#             # Put the annotated frame into the queue
#             try:
#                 self.frame_queue.put(annotated_frame, timeout=1)  # Wait for 1 second if the queue is full
#             except queue.Full:
#                 # If the queue is full, we can choose to drop the frame or handle it differently
#                 pass
#
#         cap.release()
#
#     def get_frame(self):
#         try:
#             # Get a frame from the queue, blocking if necessary
#             frame = self.frame_queue.get(timeout=1)  # Wait for 1 second if the queue is empty
#             return frame
#         except queue.Empty:
#             return None  # Return None if no frame is available
